package com.sinosoft.perfect.system._.action;

import java.sql.SQLException;

import com.sinosoft.perfect.common.system.BaseAction;
import com.sinosoft.perfect.system._.service.ILoginUserResourceService;
import com.sinosoft.perfect.system._.vo.LoginUser;
import com.sinosoft.perfect.system._.vo.ResourceURLPower;


@SuppressWarnings("serial")
public class MainPageResourceAction extends BaseAction{

	private ILoginUserResourceService iloginUserResourceService;
	
	private String resourceId;
	
	private String resourcePath;
	
	public void setIloginUserResourceService(ILoginUserResourceService iloginUserResourceService) {
		this.iloginUserResourceService = iloginUserResourceService;
	}

	public void setResourceId(String resourceId) {
		this.resourceId = resourceId;
	}		
	
	public String getResourcePath() {
		return resourcePath;
	}

	public void setResourcePath(String resourcePath) {
		this.resourcePath = resourcePath;
	}

	
	public String RedirectResource() {
		final LoginUser loginUser = (LoginUser)session.get("user");
		try {
			final ResourceURLPower resourceURLPower = 
				iloginUserResourceService.getResourceURLPower(loginUser.getUserMainId(), resourceId,loginUser.getUserType());
			session.put("power", resourceURLPower);
			this.setResourcePath(resourceURLPower.getResourceURL());
			return resourceURLPower.getResourceURL();
		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}		
		//return "resourcePage";
	}
}
